<form id="form">
<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal">
		<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
	</button>
	<small class="modal-title">
	<#if model??>
		<i class="fa fa-pencil"></i> 编辑	
	<#else>
		<i class="fa fa-plus"></i> 新增
	</#if>
	</small>
</div>
<div class="modal-body" style="height:330px;overflow-y:auto;">
	<div class="tabs-container">
		<div class="form-horizontal clearfix">
			<input type="hidden" name="id" value="<#if model??>${model.id!''}</#if>"/>
			<input type="hidden" id="store_id" name="store_id" value="${store.id}"/>
            <input type="hidden" id="wxuser_id" name="wxuser_id" value="${store.wxuser_id}"/>
            <input type="hidden" id="shop_id" name="shop_id" value="${store.shop_id}"/>
            <#if !model??>
            	<div class="alert alert-info">
                    <i class="fa fa-info-circle"></i>此店已配置${store.device_count}个SSID，还可配置${100 - store.device_count}个SSID。.
                </div>
            </#if>
			<div class="col-sm-12">
               	<div class="form-group">
                          <label class="col-sm-3 control-label">已选择门店</label>
                          <div class="col-sm-8" style="padding:8px 15px 10px 15px;">
							<span>${store.business_name}</span>
                          </div>
                </div>
                <#if model?? && model.id??>
                <div class="form-group">
                    <div class="col-sm-8 col-md-offset-3">
                        <span><font color="red">注意:修改后将会重新设置新的真实ssid，默认修改为启用状态,如果想不修改真实ssid请使用状态设置</font></span>
                    </div>
                </div>
                </#if>
                <div class="form-group">
                    <label class="col-sm-3 control-label">网络名称(SSID)</label>
                    <div class="col-sm-8">
                    	<input type="text" id="ssid" name="ssid" value="<#if model??>${model.ssid}</#if>" class="form-control requiredIcon" placeholder="请输入无线网络名称">
                    	<span>总长度32个字符以内</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">密码</label>
                    <div class="col-sm-8">
                    	<input type="text" id="password" name="password" value="<#if model??>${model.password!'WX123456'}<#else>WX123456</#if>" class="form-control requiredIcon" placeholder="请输入无线网络密码">
                    	<span>请输入8-24个字符密码</span>
                    </div>
                </div>
			</div>
		</div>
	</div>
</div>
<div class="modal-footer">
	<button class="btn btn-white" data-dismiss="modal">关闭</button>
	<button class="btn btn-primary" type="submit">保存</button>
</div>
</form>
<script>
$(function(){
	var validator = $("#form").validate({
          ignore: ".ignore",
      	  rules: {
                ssid: {
                    required: true,
                    maxlength: 32
                },
                password: {
                    required: true,
                    rangelength: [8,24]
                }
            },
            messages: {
            	ssid: {
                    required: icon + "请输入无线网络名称"
                },
                password: {
                    required: icon + "请输入无线网络密码"
                }
            },
            submitHandler: function(form){
            	//显示loading提示
                var loading = layer.load();
                var id = $("#form input[name=id]").val();
                $(form).ajaxSubmit({
               		url:"${basePath}/wxdevice/" + (id == "" ? "add" : "edit") ,
               	 	type:"POST",
               	 	dataType:"json",
               	 	success: function (resp) {
               	 		layer.close(loading);
	            		if(resp.code == 0) {
	            			$("#formModal").modal("hide");
    	            		swal({
    	                  		title: "操作成功",
    	                  		type: "success",
    	                  		showCancelButton: false,
    	                  		confirmButtonColor: '#18a689',
    	                  		confirmButtonText: '确定',
    	                  		closeOnConfirm: true
    	                  	},
    	                  	function(){
    	                  		$("#table").bootstrapTable("refresh");
    	                  	});
	            		}else if(resp.code == 1){
	            			swal("操作失败！", resp.data, "error");
	            		}else {
	            			swal("操作失败！", "未知错误", "error");
	            		}
                 	}
                });
            },
            showErrors: function(errorMap, errorList) {
          		this.defaultShowErrors();
            }
        });
})
</script>

